1.安装uwsgi

2.创建test.py文件,文件内容如下

1
2
3
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return "Hello World"

3.测试 uwsgi 是否正常 ,在终端执行
uwsgi –http :8001 –wsgi-file /data/test.py

4.执行报错,报错内容如下

1
2
3
4
uwsgi: option '--http' is ambiguous; possibilities: '--http-socket' '--https-socket-modifier2' 
'--https-socket-modifier1' '--https-socket' '--http11-socket' '--http-socket-modifier2'
'--http-socket-modifier1'
getopt_long() error

5.去解决问题=======================》》》
查看uwsgi安装位置,终端执行 :

1
2
3
4
5
      whereis uwsgi
执行结果为:
uwsgi: /usr/sbin/uwsgi /usr/lib64/uwsgi /etc/uwsgi.d /etc/uwsgi.ini
定位原因为:
上面两个uwsgi文件均缺失plugin插件,所以需要自行安装plugin插件:uwsgi-plugin-python

6.安装 uwsgi-plugin-python
提示:安装之前需要先安装 uwsgi-plugin-common 安装步骤如下:

1
2
yum install uwsgi-plugin-common
yum install uwsgi-plugin-python

7.再次执行uwsgi –http :8001 –wsgi-file /data/test.py 依旧报同样错误
8.修改命令为:uwsgi –http-socket :8001 –wsgi-file /data/test.py执行结果如下:
uwsgi: unrecognized option ‘–wsgi-file’
getopt_long() error

这是因为: 需要在上面那些未识别选项前加上 –plugin python 来告诉uWSGI 我在使用 python 插件,对于后面那些选项你要用python 插件去解析

9.再次修改命令为:
uwsgi –http-socket :8001 –plugin python –wsgi-file /data/test.py

10.浏览器访问http://IP(XXXXX):8001/
终于 成功了!!!
最后附上终端显示内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
*** Starting uWSGI 2.0.16 (64bit) on [Fri Jun 22 14:39:45 2018] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-16) on 13 February 2018 02:48:03
os: Linux-3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017
nodename: VM_0_7_centos
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /root
detected binary path: /usr/sbin/uwsgi
dropping root privileges as early as possible
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3895
your memory page size is 4096 bytes
detected max file descriptor number: 100001
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address :8001 fd 3
dropping root privileges after socket binding
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 2.7.5 (default, Apr 11 2018, 07:36:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1013a90
dropping root privileges after plugin initialization
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72920 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x1013a90 pid: 6852 (default app)
dropping root privileges after application loading
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 6852, cores: 1)